Pass correct search path to DllImportResolver for default flags on Mono#129831
Merged
elinor-fung merged 1 commit intoJun 25, 2026
Merged
Conversation
When neither the P/Invoke nor the assembly has a DefaultDllImportSearchPaths attribute, Mono passed DllImportSearchPath.AssemblyDirectory to a registered DllImportResolver instead of null. lookup_pinvoke_call_impl defaults the flags to ASSEMBLY_DIRECTORY for the built-in probing logic, and netcore_resolve_with_dll_import_resolver derived "has search flags" from (flags != 0), so the defaulted value leaked to the resolver. Combined with dotnet#114756 - which made an explicit AssemblyDirectory no longer fall back to the OS search - this broke resolvers that forward the search path to NativeLibrary.Load, such as loading iOS @rpath frameworks. Thread the existing user_specified_flags signal through to the resolver so it receives the attribute value, or null when none was specified, matching CoreCLR and NativeAOT. Fixes dotnet#129798 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Contributor
|
Tagging subscribers to this area: @dotnet/interop-contrib |
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fixes Mono’s DllImportResolver searchPath reporting so that the resolver receives null when no DefaultDllImportSearchPaths attribute is present, instead of receiving Mono’s internal default (AssemblyDirectory). This brings Mono behavior in line with the documented DllImportResolver contract and with CoreCLR/NativeAOT.
Changes:
- Mono: thread through and use
user_specified_flagsto decide whether to pass search flags to the resolver (instead offlags != 0). - Tests: add an interop test validating that the resolver observes
AssemblyDirectory,System32,LegacyBehavior, andnullbased on attribute presence/value.
Show a summary per file
| File | Description |
|---|---|
| src/mono/mono/metadata/native-library.c | Uses the existing user_specified_flags signal to decide whether the resolver should receive a non-null searchPath. |
| src/tests/Interop/DllImportSearchPaths/DllImportSearchPathsTest.cs | Adds coverage to assert the resolver’s observed searchPath matches DefaultDllImportSearchPaths (or null when absent). |
Copilot's findings
- Files reviewed: 2/2 changed files
- Comments generated: 2
Member
Author
|
/backport to release/10.0 |
Contributor
|
Started backporting to |
4 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
On Mono, when no search flags are user-specified,
lookup_pinvoke_call_impldefaults the flags toDLLIMPORTSEARCHPATH_ASSEMBLY_DIRECTORYfor the built-in probing logic.netcore_resolve_with_dll_import_resolverthen derived whether to report search flags to the resolver fromflags != 0, so the explicitAssemblyDirectoryvalue was passed to the resolver instead ofnull. The expectedDllImportResolvercontract is thatsearchPathis the attribute value, ornullwhen neither the P/Invoke nor the assembly has the attribute.After #114756, specifying only
AssemblyDirectorymeant only assembly directory. This means that when a resolver that forwards the (wrongly non-null)AssemblyDirectorytoNativeLibrary.Load, it no longer does the default search (baredlopen/LoadLibrary).This change passes the
user_specified_flagsvalue through to the resolver invocation and uses it for "has search flags", so the resolver receives the attribute value ornullfor non-user-specified.cc @dotnet/appmodel @AaronRobinsonMSFT
See #129798. We should backport to 10.
Note
This pull request was created with GitHub Copilot.